<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>傻强物流信息管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/assets/js/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/assets/js/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/assets/css/global.css" media="all">
    <link rel="stylesheet" href="/assets/css/table.css"/>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="admin-main">
    <form id="form1" class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">快递公司</label>
            <div class="layui-input-block">
                <div class="layui-input-inline">
                    <input type="text" name="expressModelFile" lay-verify="required" jq-error="请选择栏目模板"
                           placeholder="请选择栏目模板" autocomplete="off" class="layui-input ">
                </div>
                <button type="button" class="layui-btn layui-btn-primary" id="expressModelFileBtn">选择文件</button>
            </div>
        </div>
        <div class="layui-form-item">
            <button type="button" class="layui-btn" id="editTopicBtn">开始上传</button>

            <!--<button class="layui-btn" id="editTopicBtn" lay-submit="" lay-filter="add">立即提交</button>-->
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>

        <div class="layui-form-item" id="resultList" style="display: none;">
            <input type="hidden" name="expressModelNewFile" readonly/>
            <a href="" id="jumpUrl" target="_self">下载查询结果文件</a>
        </div>
    </form>
</div>

<script type="text/javascript" src="/assets/js/layui/layui.js"></script>
<script>
    layui.cache.page = 'module';
    layui.config({
        version: "1.0.0",
        base: '/assets/js/'
    });
    layui.use(['jquery', 'layer', 'upload', 'oneplatform'], function () {
        var layer = layui.layer
            , $ = layui.jquery
            , upload = layui.upload
            , oneplatform = layui.oneplatform;

        //选择文件，栏目模板
        var uploadInst = upload.render({
            elem: '#expressModelFileBtn',
            url: '/file/fileUpload',
            auto: false,//选择文件后不自动上传
            accept: 'file',
            multiple: false,
            bindAction: '#editTopicBtn',//指向一个按钮触发上传
            choose: function (res) {
                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                res.preview(function (index, file, result) {
                    $('input[name=expressModelFile]').val(file.name);
                });
            },
            // 上传成功回调, 每个文件提交一次触发一次
            done: function (res, index, upload) {

                // // 假设code=200代表上传成功
                if (res.code == 200) {
                    oneplatform.success(res.msg || '操作成功');

                    // 上传的原始文件名称
                    var fileName = $('input[name=expressModelFile]').val();

                    // 显示响应后的文件下载链接
                    $("#resultList").show();
                    $('input[name=expressModelNewFile]').val(res.data.exportFile);

                    $('#jumpUrl').attr('href', "/file/fileDownLoad?fileName=" +res.data.fileName);
                    $("#jumpUrl").text('下载查询结果文件[' + fileName + ']');
                } else {
                    oneplatform.error(res.msg);
                }
            },
            // 上传失败毁掉啊
            error: function (res, index, upload) {
                oneplatform.error("系统错误");
            }
        });
    });
</script>
</body>
</html>